/* CoralCube | Massively Multiplayer Online Role-Playing Game(MMORPG) Emulator.
|* 
|* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
|*               2008-2010 TrinityCore <http://www.trinitycore.org/>
|*               2008-2010 CoralCube <http://www.CoralCube.com/>
|*
|* This program is free software. You can redistribute it and/or modify it under the terms of 
|* the GNU General Public License as published by the Free Software Foundation, either 
|* version 2 of the License.
|*
|* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, 
|* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
|* See the GNU General Public License for more details.
|*
|* You should have received a copy of the GNU General Public License along with this program. 
|* If not, see <http://www.gnu.org/licenses/>.
|*/

#include "Common.h"
#include "Database/DatabaseEnv.h"

#include "Configuration/Config.h"
#include "Log.h"
#include "SystemConfig.h"
#include "Util.h"
#include "SignalHandler.h"
#include "RealmList.h"
#include "RealmAcceptor.h"
#include "Check.h"
#include "ProgressBar.h"

#include <ace/Dev_Poll_Reactor.h>
#include <ace/TP_Reactor.h>
#include <ace/ACE.h>
#include <ace/Sig_Handler.h>

#include <openssl/opensslv.h>
#include <openssl/crypto.h>

#ifdef _WIN32
#include "ServiceWin32.h"
char serviceName[] = "AuthServer";
char serviceLongName[] = "AuthServer service";
char serviceDescription[] = "Massive Network Game Object Server";
/*
* -1 - not in service mode
*  0 - stopped
*  1 - running
*  2 - paused
*/
int m_ServiceStatus = -1;
#endif

bool StartDB();
void LoadConfigSettings();

bool stopEvent = false;                                     ///< Setting it to true stops the server

LoginDatabaseWorkerPool LoginDatabase;                                 ///< Accessor to the realm server database
ConfigDatabaseWorkerPool ConfigDatabase;                               ///< Accessor to the config database
WorldDatabaseWorkerPool WorldDatabase;
CharacterDatabaseWorkerPool CharacterDatabase;

/// Handle realmd's termination signals
class RealmdSignalHandler : public Core::SignalHandler
{
public:
    virtual void HandleSignal(int SigNum)
    {
        switch (SigNum)
        {
        case SIGINT:
        case SIGTERM:
            stopEvent = true;
            break;
#ifdef _WIN32
        case SIGBREAK:
            if (m_ServiceStatus != 1)
                stopEvent = true;
            break;
#endif /* _WIN32 */
        }
    }
};

/// Print out the usage string for this program on the console.
void usage(const char *prog)
{
    sLog.outString("Usage: \n %s [<options>]\n"
        "    -c config_file           use config_file as configuration file\n\r"
#ifdef _WIN32
        "    Running as service functions:\n\r"
        "    --service                run as service\n\r"
        "    -s install               install service\n\r"
        "    -s uninstall             uninstall service\n\r"
#endif
        ,prog);
}

/// Launch the realm server
extern int main(int argc, char **argv)
{
    sLog.SetLogDB(false);

    ///- Command line parsing to get the configuration file name
    char const *cfg_file = _SETTINGS_FILE;
    int c = 1;

    while (c < argc)
    {
        if (strcmp(argv[c], "-c") == 0)
        {
            if (++c >= argc)
            {
                sLog.outError("Runtime-Error: -c option requires an input argument");
                usage(argv[0]);
                return 1;
            }
            else
                cfg_file = argv[c];
        }

#ifdef _WIN32
        ////////////
        //Services//
        ////////////
        if (strcmp(argv[c], "-s") == 0)
        {
            if (++c >= argc)
            {
                sLog.outError("Runtime-Error: -s option requires an input argument");
                usage(argv[0]);
                return 1;
            }
            if (strcmp(argv[c], "install") == 0)
            {
                if (WinServiceInstall())
                    sLog.outString("Installing service");
                return 1;
            }
            else if (strcmp(argv[c], "uninstall") == 0)
            {
                if (WinServiceUninstall())
                    sLog.outString("Uninstalling service");
                return 1;
            }
            else
            {
                sLog.outError("Runtime-Error: unsupported option %s", argv[c]);
                usage(argv[0]);
                return 1;
            }
        }

        if (strcmp(argv[c], "--service") == 0)
        {
            WinServiceRun();
        }
        ////
#endif
        ++c;
    }

    if (!sConfig.SetSource(cfg_file))
    {
        sLog.outError("Invalid or missing configuration file : %s", cfg_file);
        sLog.outError("Verify that the file exists and has \'[SettingConf]\' written in the top of the file!");
        return 1;
    }

    ///- Check the version of the configuration file
    sCheck.CheckConfigVersion(sConfig.GetIntDefault("ConfVersion", 0), _SETTINGS_VERSION);

    ///- Initialize the database connection
    if (!StartDB())
        return 1;

    ///- Read important Logging Settings
    sConfigDB.logs_dir                                   = "logs";
    sConfigDB.log_file                                   = "Auth.Server.log";
    sConfigDB.log_conf                                   = "Auth.Config.log";
    sConfigDB.log_sql                                    = "Auth.SqlDriver.log";
    sConfigDB.console_colors                             = "13 8 9 5";
    sConfigDB.setBoolConfig(CONFIG_LOG_FILE_TIMESTAMP,   false);
    sConfigDB.setBoolConfig(CONFIG_LOG_CONFIG_TIMESTAMP, false);
    sConfigDB.setBoolConfig(CONFIG_LOG_SQL_TIMESTAMP,    false);
    sConfigDB.setIntConfig(CONFIG_LOG_CONSOLE_LEVEL,     1);
    sConfigDB.setIntConfig(CONFIG_LOG_FILE_LEVEL,        0);

    if (QueryResult qResult = ConfigDatabase.Query("SELECT name,value FROM 00_authserver_settings"))
    {
        Field *fields = qResult->Fetch();

        if (fields[0].GetString() == "Log.Dir")
            if (fields[1].GetString() != sConfigDB.logs_dir)
                sConfigDB.logs_dir = fields[1].GetString();

        if (fields[0].GetString() == "LogFile.Auth")
            if (fields[1].GetString() != sConfigDB.log_file)
                sConfigDB.log_file = fields[1].GetString();

        if (fields[0].GetString() == "LogFile.Config")
            if (fields[1].GetString() != sConfigDB.log_conf)
                sConfigDB.log_conf = fields[1].GetString();

        if (fields[0].GetString() == "LogFile.SqlDriver")
            if (fields[1].GetString() != sConfigDB.log_sql)
                sConfigDB.log_sql = fields[1].GetString();

        if (fields[0].GetString() == "Console.Colors")
            if (fields[1].GetString() != sConfigDB.console_colors)
                sConfigDB.console_colors = fields[1].GetString();

        if (fields[0].GetString() == "LogFile.Auth.Timestamp")
            if (fields[1].GetBool())
                sConfigDB.setBoolConfig(CONFIG_LOG_FILE_TIMESTAMP, true);

        if (fields[0].GetString() == "LogFile.Config.Timestamp")
            if (fields[1].GetBool())
                sConfigDB.setBoolConfig(CONFIG_LOG_CONFIG_TIMESTAMP, true);

        if (fields[0].GetString() == "LogFile.SqlDriver.Timestamp")
            if (fields[1].GetBool())
                sConfigDB.setBoolConfig(CONFIG_LOG_SQL_TIMESTAMP, true);

        if (fields[0].GetString() == "Console.Level")
            if (fields[1].GetUInt32() != sConfigDB.getIntConfig(CONFIG_LOG_CONSOLE_LEVEL))
                sConfigDB.setIntConfig(CONFIG_LOG_CONSOLE_LEVEL, fields[1].GetUInt32());

        if (fields[0].GetString() == "LogFile.Level")
            if (fields[1].GetUInt32() != sConfigDB.getIntConfig(CONFIG_LOG_FILE_LEVEL))
                sConfigDB.setIntConfig(CONFIG_LOG_FILE_LEVEL, fields[1].GetUInt32());
    }
    ///- Initialize log settings
    sLog.Initialize(true);

    ///- Check Database Required Fields
    sCheck.CheckDatabaseVersion(1);     // auth
    sCheck.CheckDatabaseVersion(2);     // config

    sLog.outString("Using configuration file %s.", cfg_file);

    sLog.outString("%s (logon-daemon)", _FULLVERSION);
    sLog.outString("<Ctrl-C> to stop.");
    sLog.outString();
    sLog.outString("                     __ ");
    sLog.outString("                    /\\_\\ ");
    sLog.outString("         ___________\\/_/_  ________     _______  __    __ ");
    sLog.outString("        /\\__   ____ `\\/\\ \\/\\   ____`\\ /\\`  __  \\/\\ `\\ /\\ \\ ");
    sLog.outString("        \\/_/\\  \\__/\\  \\ \\ \\ \\  \\__/\\ \\\\ \\  \\/\\  \\ \\  `\\ \\ \\ ");
    sLog.outString("           \\ \\  \\_\\/  /\\ \\ \\ \\  \\_\\/ /_\\ \\  \\ \\  \\ \\ \\ `\\\\ \\ ");
    sLog.outString("            \\ \\   ___, `\\ \\ \\ \\   ___, `\\ \\  \\ \\  \\ \\ \\\\,`\\ \\ ");
    sLog.outString("             \\ \\  \\__/\\  \\ \\ \\ \\  \\__/\\  \\ \\  \\_\\  \\ \\ \\,\\,  \\ ");
    sLog.outString("              \\ \\  \\ \\ \\  \\ \\_\\ \\  \\_\\_\\  \\ \\,____,/\\ \\_\\\\ \\,_\\ ");
    sLog.outString("               \\ \\__\\ \\ \\__\\/_/\\ \\________/\\/_____/  \\/_/ \\/__/ ");
    sLog.outString("                \\/__/  \\/__/    \\/_______/  %s  ", _PROJECTPAGE);
    sLog.outString("             ________   _______  ________   _______ ");
    sLog.outString("            /\\   ____\\/\\`  __  \\/\\   ___ `\\/\\  ____\\ ");
    sLog.outString("            \\ \\  \\___/\\ \\  \\/\\  \\ \\  \\_/\\  \\ \\ \\___/ ");
    sLog.outString("             \\ \\  \\    \\ \\  \\ \\  \\ \\  \\\\/  /\\ \\  __\\ ");
    sLog.outString("              \\ \\  \\    \\ \\  \\ \\  \\ \\   __, `\\ \\ \\_/___ ");
    sLog.outString("               \\ \\  \\    \\ \\,____,/\\ \\  \\_/\\  \\ \\______\\ ");
    sLog.outString("                \\ \\  \\    \\/_____/  \\ \\__\\\\ \\__\\/______/ ");
    sLog.outString("                 \\ \\  \\     LOGON    \\/__/ \\/__/ %s ", _PROJECTYEARS);
    sLog.outString("                  \\ \\  \\______________________________________ ");
    sLog.outString("                   \\ \\______ Codename:  %s  ____\\ ", _CODENAME);
    sLog.outString("                    \\/________________________________________/ ");
    sLog.outString();
    sLog.outDetail("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));

#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
    ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true);
#else
    ACE_Reactor::instance(new ACE_Reactor(new ACE_TP_Reactor(), true), true);
#endif

    sLog.outBasic("Max allowed open files is %d", ACE::max_handles());

    /// - Initialize Configuration settings
    LoadConfigSettings();

    /// AuthServer PID file creation
    std::string pidfile = sConfigDB.pidfile;

    if (!pidfile.empty())
    {
        uint32 pid = CreatePIDFile(pidfile);
        if (!pid)
        {
            sLog.outError("Cannot create PID file %s.\n", pidfile.c_str());
            return 1;
        }

        sLog.outString("Daemon PID: %u\n", pid);
    }

    ///- Initialize the log database
    sLog.SetLogDBLater(sConfigDB.getBoolConfig(CONFIG_LOG_DB_ENABLE)); // set var to enable DB logging once startup finished.
    sLog.SetLogDB(false);
    sLog.SetRealmID(0);                                               // ensure we've set realm to 0 (realmd realmid)

    ///- Get the list of realms for the server
    sRealmList->Initialize(sConfigDB.getIntConfig(CONFIG_AUTH_REALMS_STATE_UPDATE_DELAY));
    if (sRealmList->size() == 0)
    {
        sLog.outError("No valid realms specified.");
        return 1;
    }

    ///- Launch the listening network socket
    RealmAcceptor acceptor;

    uint16 rmport = sConfigDB.getIntConfig(CONFIG_AUTH_PORT);
    std::string bind_ip = sConfigDB.bindip;

    ACE_INET_Addr bind_addr(rmport, bind_ip.c_str());

    if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
    {
        sLog.outError("Core realm can not bind to %s:%d", bind_ip.c_str(), rmport);
        return 1;
    }

    // Initialise the signal handlers
    RealmdSignalHandler SignalINT, SignalTERM;
#ifdef _WIN32
    RealmdSignalHandler SignalBREAK;
#endif /* _WIN32 */

    // Register realmd's signal handlers
    ACE_Sig_Handler Handler;
    Handler.register_handler(SIGINT, &SignalINT);
    Handler.register_handler(SIGTERM, &SignalTERM);
#ifdef _WIN32
    Handler.register_handler(SIGBREAK, &SignalBREAK);
#endif /* _WIN32 */

    ///- Handle affinity for multiple processors and process priority on Windows
#ifdef _WIN32
    {
        HANDLE hProcess = GetCurrentProcess();

        uint32 Aff = sConfigDB.getIntConfig(CONFIG_AUTH_USE_PROCESSORS);
        if (Aff > 0)
        {
            ULONG_PTR appAff;
            ULONG_PTR sysAff;

            if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
            {
                ULONG_PTR curAff = Aff & appAff;            // remove non accessible processors

                if (!curAff)
                {
                    sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x",Aff,appAff);
                }
                else
                {
                    if (SetProcessAffinityMask(hProcess, curAff))
                        sLog.outString("Using processors (bitmask, hex): %x", curAff);
                    else
                        sLog.outError("Can't set used processors (hex): %x", curAff);
                }
            }
            sLog.outString();
        }

        if(sConfigDB.getBoolConfig(CONFIG_AUTH_PROCESS_PRIORITY))
        {
            if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
                sLog.outString("AuthServer process priority class set to HIGH");
            else
                sLog.outError("Can't set AuthServer process priority class.");
            sLog.outString();
        }
    }
#endif

    // maximum counter for next ping
    uint32 numLoops = (sConfigDB.getIntConfig(CONFIG_AUTH_MAX_PING_TIME) * (MINUTE * 1000000 / 100000));
    uint32 loopCounter = 0;

    // possibly enable db logging; avoid massive startup spam by doing it here.
    if (sLog.GetLogDBLater())
    {
        sLog.outString("Enabling database logging...");
        sLog.SetLogDBLater(false);
        // login db needs thread for logging
        sLog.SetLogDB(true);
    }
    else
        sLog.SetLogDB(false);

    ///- Wait for termination signal
    while (!stopEvent)
    {
        // dont move this outside the loop, the reactor will modify it
        ACE_Time_Value interval(0, 100000);

        if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1)
            break;

        if ((++loopCounter) == numLoops)
        {
            loopCounter = 0;
            sLog.outDetail("Ping MySQL to keep connection alive");
            LoginDatabase.KeepAlive();
        }
#ifdef _WIN32
        if (m_ServiceStatus == 0)
            stopEvent = true;

        while (m_ServiceStatus == 2)
            Sleep(1000);
#endif
    }

    ///- Close the Database Pool
    LoginDatabase.Close();
    ConfigDatabase.Close();

    sLog.outString("Halting process...");
    return 0;
}

/// Initialize connection to the database
bool StartDB()
{
    std::string dbstring;
    uint8 worker_threads, connections;

    dbstring = sConfig.GetStringDefault("LoginDatabaseInfo", "");
    if (dbstring.empty())
    {
        sLog.outError("AuthServer database info not specified");
        return false;
    }

    worker_threads = sConfig.GetIntDefault("LoginDatabase.WorkerThreads", 1);
    if (worker_threads < 1 || worker_threads > 32)
    {
        sLog.outError("Improper value specified for LoginDatabase.WorkerThreads, defaulting to 1.");
        worker_threads = 1;
    }

    connections = sConfig.GetIntDefault("LoginDatabase.Connections", 1);
    if (connections < 1 || connections > 32)
    {
        sLog.outError("Improper value specified for LoginDatabase.Connections, defaulting to 2.");
        connections = 2;
    }

    /// NOTE: While authserver is singlethreaded you should keep synch_threads == 1. Increasing it is just silly since only 1 will be used ever.
    if (!LoginDatabase.Open(dbstring.c_str(), worker_threads, connections))
    {
        sLog.outError("Cannot connect to auth database");
        return false;
    }
    
    dbstring = sConfig.GetStringDefault("ConfigDatabaseInfo", "");
    if (dbstring.empty())
    {
        sLog.outError("Config database info not specified");
        return false;
    }

    worker_threads = sConfig.GetIntDefault("ConfigDatabase.WorkerThreads", 1);
    if (worker_threads < 1 || worker_threads > 32)
    {
        sLog.outError("Improper value specified for ConfigDatabase.WorkerThreads, defaulting to 1.");
        worker_threads = 1;
    }

    connections = sConfig.GetIntDefault("ConfigDatabase.Connections", 1);
    if (connections < 1 || connections > 32)
    {
        sLog.outError("Improper value specified for ConfigDatabase.Connections, defaulting to 2.");
        connections = 2;
    }

    //- Config has singlethreaded synchronous DB access, hence synch_threads
    if (!ConfigDatabase.Open(dbstring.c_str(), worker_threads, connections))
    {
        sLog.outError("Cannot connect to config database");
        return false;
    }

    return true;
}

void LoadConfigSettings()
{
    sLog.outConfig("-== Load Logon Configurations Settings ==-");

    QueryResult c_00_authserver_settings = ConfigDatabase.Query("SELECT name,value FROM 00_authserver_settings");

    sConfigDB.setIntConfig(CONFIG_AUTH_USE_PROCESSORS,            0);
    sConfigDB.setIntConfig(CONFIG_AUTH_PORT,                      3724);
    sConfigDB.setIntConfig(CONFIG_AUTH_REALMS_STATE_UPDATE_DELAY, 20);
    sConfigDB.setIntConfig(CONFIG_AUTH_WRONG_PASS_MAX_COUNT,      0);
    sConfigDB.setIntConfig(CONFIG_AUTH_WRONG_PASS_BAN_TIME,       600);
    sConfigDB.setIntConfig(CONFIG_AUTH_MAX_PING_TIME,             20);
    sConfigDB.setBoolConfig(CONFIG_AUTH_PROCESS_PRIORITY,         true);
    sConfigDB.setBoolConfig(CONFIG_LOG_DB_ENABLE,                 false);
    sConfigDB.setBoolConfig(CONFIG_AUTH_WRONG_PASS_BAN_TYPE,      false);
    sConfigDB.pidfile                                             = "";
    sConfigDB.bindip                                              = "0.0.0.0";

    if (c_00_authserver_settings)                                                 
    {
        sLog.outString("Loading authserver settings...");
        barGoLink bar(c_00_authserver_settings->GetRowCount());
        uint32 count = 0;
        do
        {
            bar.step();
            Field *fields = c_00_authserver_settings->Fetch();

            if (fields[0].GetString() == "UseProcessors")
                if (fields[1].GetUInt32() != sConfigDB.getIntConfig(CONFIG_AUTH_USE_PROCESSORS))
                    sConfigDB.setIntConfig(CONFIG_AUTH_USE_PROCESSORS, fields[1].GetUInt32());

            if (fields[0].GetString() == "ProcessPriority")
                if (!fields[1].GetBool())
                    sConfigDB.setBoolConfig(CONFIG_AUTH_PROCESS_PRIORITY, false);

            if (fields[0].GetString() == "PidFile")
                if (fields[1].GetString() != sConfigDB.pidfile)
                    sConfigDB.pidfile = fields[1].GetString();

            if (fields[0].GetString() == "BindIP")
                if (fields[1].GetString() != sConfigDB.bindip)
                    sConfigDB.bindip = fields[1].GetString();

            if (fields[0].GetString() == "RealmServerPort")
                if (fields[1].GetUInt32() != sConfigDB.getIntConfig(CONFIG_AUTH_PORT))
                    sConfigDB.setIntConfig(CONFIG_AUTH_PORT, fields[1].GetUInt32());

            if (fields[0].GetString() == "EnableLogDB")
                if (fields[1].GetBool())
                    sConfigDB.setBoolConfig(CONFIG_LOG_DB_ENABLE, true);

            if (fields[0].GetString() == "RealmsStateUpdateDelay")
                if (fields[1].GetUInt32() != sConfigDB.getIntConfig(CONFIG_AUTH_REALMS_STATE_UPDATE_DELAY))
                    sConfigDB.setIntConfig(CONFIG_AUTH_REALMS_STATE_UPDATE_DELAY, fields[1].GetUInt32());

            if (fields[0].GetString() == "WrongPass.MaxCount")
                if (fields[1].GetUInt32() != sConfigDB.getIntConfig(CONFIG_AUTH_WRONG_PASS_MAX_COUNT))
                    sConfigDB.setIntConfig(CONFIG_AUTH_WRONG_PASS_MAX_COUNT, fields[1].GetUInt32());

            if (fields[0].GetString() == "WrongPass.BanTime")
                if (fields[1].GetUInt32() != sConfigDB.getIntConfig(CONFIG_AUTH_WRONG_PASS_BAN_TIME))
                    sConfigDB.setIntConfig(CONFIG_AUTH_WRONG_PASS_BAN_TIME, fields[1].GetUInt32());

            if (fields[0].GetString() == "WrongPass.BanType")
                if (fields[1].GetBool())
                    sConfigDB.setBoolConfig(CONFIG_AUTH_WRONG_PASS_BAN_TYPE, true);

            if (fields[0].GetString() == "MaxPingTime")
                if (fields[1].GetUInt32() != sConfigDB.getIntConfig(CONFIG_AUTH_MAX_PING_TIME))
                    sConfigDB.setIntConfig(CONFIG_AUTH_MAX_PING_TIME, fields[1].GetUInt32());

            ++count;
        }
        while (c_00_authserver_settings->NextRow());

        sLog.outString();
        sLog.outString(">> Loaded %u authserver settings", count);
    }   

    sLog.outConfig("BindIp is set to -------------------- %s", sConfigDB.StringEmpty(sConfigDB.bindip.c_str()));
    sLog.outConfig("Console.Colors is set to ------------ %s", sConfigDB.StringEmpty(sConfigDB.console_colors.c_str()));
    sLog.outConfig("Console.Level is set to ------------- %u", sConfigDB.getIntConfig(CONFIG_LOG_CONSOLE_LEVEL));
    sLog.outConfig("EnableLogDB is set to --------------- %s", sConfigDB.ToString(sConfigDB.getBoolConfig(CONFIG_LOG_DB_ENABLE)));
    sLog.outConfig("Log.Dir is set to ------------------- %s", sConfigDB.StringEmpty(sConfigDB.logs_dir.c_str()));
    sLog.outConfig("LogFile.Auth is set to -------------- %s", sConfigDB.StringEmpty(sConfigDB.log_file.c_str()));
    sLog.outConfig("LogFile.Auth.Timestamp is set to ---- %s", sConfigDB.ToString(sConfigDB.getBoolConfig(CONFIG_LOG_FILE_TIMESTAMP)));
    sLog.outConfig("LogFile.Config is set to ------------ %s", sConfigDB.StringEmpty(sConfigDB.log_conf.c_str()));
    sLog.outConfig("LogFile.Config.Timestamp is set to -- %s", sConfigDB.ToString(sConfigDB.getBoolConfig(CONFIG_LOG_CONFIG_TIMESTAMP)));
    sLog.outConfig("LogFile.Level is set to ------------- %u", sConfigDB.getIntConfig(CONFIG_LOG_FILE_LEVEL));
    sLog.outConfig("LogFile.SqlDriver is set to --------- %s", sConfigDB.StringEmpty(sConfigDB.log_sql.c_str()));
    sLog.outConfig("LogFile.SqlDriver.Timestamp is set to %s", sConfigDB.ToString(sConfigDB.getBoolConfig(CONFIG_LOG_SQL_TIMESTAMP)));
    sLog.outConfig("MaxPingTime is set to --------------- %u", sConfigDB.getIntConfig(CONFIG_AUTH_MAX_PING_TIME));
    sLog.outConfig("PidFile is set to ------------------- %s", sConfigDB.StringEmpty(sConfigDB.pidfile.c_str()));
    sLog.outConfig("ProcessPriority is set to ----------- %s", sConfigDB.ToString(sConfigDB.getBoolConfig(CONFIG_AUTH_PROCESS_PRIORITY)));
    sLog.outConfig("RealmServerPort is set to ----------- %u", sConfigDB.getIntConfig(CONFIG_AUTH_PORT));
    sLog.outConfig("RealmsStateUpdateDelay is set to ---- %u", sConfigDB.getIntConfig(CONFIG_AUTH_REALMS_STATE_UPDATE_DELAY));
    sLog.outConfig("UseProcessors is set to ------------- %u", sConfigDB.getIntConfig(CONFIG_AUTH_USE_PROCESSORS));
    sLog.outConfig("WrongPass.BanTime is set to --------- %u", sConfigDB.getIntConfig(CONFIG_AUTH_WRONG_PASS_BAN_TIME));
    sLog.outConfig("WrongPass.BanType is set to --------- %s", sConfigDB.ToString(sConfigDB.getBoolConfig(CONFIG_AUTH_WRONG_PASS_BAN_TYPE)));
    sLog.outConfig("WrongPass.MaxCount is set to -------- %u", sConfigDB.getIntConfig(CONFIG_AUTH_WRONG_PASS_MAX_COUNT));
}
